import React, { Component } from 'react'
import { Switch, Route, Redirect } from 'react-router-dom'
import { Layout } from 'antd'
import LeftNav from '../../components/left-nav'
import Header from '../../components/header'
import Home from '../home/home'
import Category from '../category/category'
import Product from '../product/product'
import Role from '../role/role'
import User from '../user/user'
import Bar from '../charts/bar'
import Line from '../charts/line'
import Pie from '../charts/pie'
import Order from '../order/order'

import memeryUtils from '../../utils/memeryUtils'

const { Footer, Sider, Content } = Layout

export default class Admin extends Component {
  render() {
    const user = memeryUtils.user
    if (!user._id) {
      //如果不是登录状态就直接跳转到登录界面
      return <Redirect to="/login" />
    }

    return (
      <Layout style={{ height: '100%' }}>
        <Sider>
          <LeftNav />
        </Sider>
        <Layout>
          <Header />
          <Content style={{ margin:'20px 20px 0 20px', backgroundColor: '#fff' }}>
            <Switch>
              <Route exact path="/" component={Home} />
              <Route path="/home" component={Home} />
              <Route path="/category" component={Category} />
              <Route path="/product" component={Product} />
              <Route path="/role" component={Role} />
              <Route path="/user" component={User} />
              <Route path="/charts/bar" component={Bar} />
              <Route path="/charts/line" component={Line} />
              <Route path="/charts/pie" component={Pie} />
              <Route path="/order" component={Order} />
              <Redirect to="/" />
            </Switch>
          </Content>
          <Footer style={{color:'#ccc', textAlign:'center'}}>请使用谷歌浏览器获取最佳的使用体验</Footer>
        </Layout>
      </Layout>
    )
  }
}
